package com.zggk.lzz.lzml;

/**
 * Created by 张成昆 on 2021-4-2.
 */

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;


import com.zggk.lzz.R;
import com.zggk.lzz.util.Utils;

import java.util.ArrayList;

/**
 * 路线 病害筛选popwindow
 * Created by dongxiaoqing on 2018/10/28.
 */

public class SeasonpPopwindow extends PopupWindow{
    private Activity activity;
    private ArrayList<String> listDataStr;
    private ListView listView;
    private SeasonpAdapter adapter;
    private SeasonpListener listener;
//    private View viewLay;
    private int Position;
    public SeasonpPopwindow(Activity activity,ArrayList<String> listDataStr,SeasonpListener listener){
        this.activity = activity;
        this.listDataStr=listDataStr;
        this.listener=listener;
        View contentView = LayoutInflater.from(activity).inflate(
                R.layout.seasonp_pop_layout, null);
        setContentView(contentView);
        setWidth(Utils.getWidth(activity));
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
//        setFocusable(true);
//        setTouchable(true);
//        setOutsideTouchable(true);
        setBackgroundDrawable(new ColorDrawable(0));
        initViews(contentView);
    }

    private void initViews(View contentView){
        listView=contentView.findViewById(R.id.season_listview);
//        viewLay=contentView.findViewById(R.id.view_lay);
        adapter=new SeasonpAdapter(activity,listDataStr);
        listView.setAdapter(adapter);
        adapter.setCurrentPosition(0);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Position =position;
                adapter.setCurrentPosition(position);
                listener.selectPosition(Position);
            }
        });

        setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

            }
        });
//        viewLay.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                close();
//            }
//        });
    }

    /**
     * 显示筛选窗口
     */
    public void show(View anchor) {
        if (isShowing()) {
            return;
        }
        if (anchor != null) {
            showAsDropDown(anchor);
        }
    }

    /**
     * 关闭筛选窗口
     */
    public void close() {
        if (isShowing()) {
            dismiss();
        }
    }

    public void notifityData(){
        adapter.notifyDataSetChanged();
    }
}


